using System;

namespace ErrorDumper {
    public static class ExceptionHandler {

        private static readonly object _syncRoot = new object();
        private static IExceptionHandler _current;

        public static IExceptionHandler Current {
            get {
                lock (_syncRoot)
                    return _current ?? (_current = new DefaultExceptionHandler());
            }
            set {
                lock (_syncRoot)
                    _current = value;
            }
        }

        public static void Reset() {
            Current = null;
        }

        public static bool IsDefault {
            get { return Current.GetType() == typeof(DefaultExceptionDataSource); }
        }

        #region HandleExceptionSafely

        public static string HandleExceptionSafely(Exception exception) {
            return Current.HandleExceptionSafely(exception);
        }

        public static string HandleExceptionSafely(
            ExceptionPropertyCollection properties, Exception exception) {
            return Current.HandleExceptionSafely(properties, exception);
        }

        public static string HandleExceptionSafely(
            ExceptionPropertyCollection properties, string content) {
            return Current.HandleExceptionSafely(properties, content);
        }

        public static string HandleExceptionSafely(ExceptionPropertyCollection properties) {
            return Current.HandleExceptionSafely(properties);
        }

        #endregion

        #region HandleExceptionAsync

        public static void HandleExceptionAsync(Exception exception) {
            Current.HandleExceptionAsync(exception);
        }

        public static void HandleExceptionAsync(
            ExceptionPropertyCollection properties, Exception exception) {
            Current.HandleExceptionAsync(properties, exception);
        }

        public static void HandleExceptionAsync(
            ExceptionPropertyCollection properties, string content) {
            Current.HandleExceptionAsync(properties, content);
        }

        public static void HandleExceptionAsync(ExceptionPropertyCollection properties) {
            Current.HandleExceptionAsync(properties);
        }

        #endregion
    }
}